#include<bits/stdc++.h>
using namespace std;
int k,n,x,m,aa,bb,l,vv,d[100010],v[100010],a[100010],p[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>k;
    while(k--){
        cin>>n>>m>>l>>vv;
        for(int i=1;i<=n;i++)cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)cin>>p[i];
        x=0;
        aa=0;bb=0;
        for(int i=1;i<=n;i++){
            if(a[i]>=0){
                if(p[m]>=d[i]&&sqrt(v[i]*v[i]+2*a[i]*(p[m]-d[i]))>vv){
                    x++;
                    aa=1;
                }
            }
            else if(p[1]<=d[i]&&sqrt(v[i]*v[i]+2*a[i]*(d[i]-p[1]))>vv){
                        x++;
                        bb=1;
                    }
        }
        cout<<x<<" "<<m-aa-bb<<"\n";
    }
    return 0;
}
